package com.iflytek.zwxu.controller.api;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iflytek.zwxu.api.UserService;
import com.iflytek.zwxu.domin.BaseResult;
import com.iflytek.zwxu.domin.UserVO;

@Controller
@RequestMapping("/api/user")
public class ApiUserController {
	@Resource
	private UserService userService;
	
	

	@RequestMapping("/list")
	@ResponseBody
	public Object list(HttpServletRequest request, HttpServletResponse response) {
		System.out.println(userService);
		List<UserVO> list  = userService.getUsers();
		/*Map<String, Object> data = new LinkedHashMap<String, Object>();
		data.put("userList", list);
		data.put("success", true);*/
		return list;
	}
	
	@RequestMapping("/insert")
	@ResponseBody
	public Object insert(HttpServletRequest request, HttpServletResponse response,UserVO vo) {

		BaseResult result  = userService.insert(vo);
		return result;
	}
	
	@RequestMapping("/queryByID")
	@ResponseBody
	public Object queryByID(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		UserVO vo = userService.queryById(id);
		return vo;
	}
	
	@RequestMapping("/update")
	@ResponseBody
	public Object update(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String name = request.getParameter("name");
		BaseResult result  = userService.update(id,name);
		return result;
	}
	
	@RequestMapping("/delete")
	@ResponseBody
	public Object delete(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		BaseResult result  = userService.delete(id);
		return result;
	}
}
